package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqNotice;
import cloud.maque.admin.service.MqNoticeService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公告接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/notice")
@Api(tags = "运维-公告接口")
public class NoticeController {


    @Autowired
    MqNoticeService noticeService;


    @PostMapping("/list")
    @ApiOperation(value = "公告查询")
    @TenantQuery
    public ResponseBodyVo<PageInfo<MqNotice>> page(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqNotice> pageReq) {
        return ResponseBodyVo.Success(noticeService.page(pageReq));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "公告详情")
    public ResponseBodyVo<MqNotice> Detail(@RequestParam("id") String noticeId) {
        return ResponseBodyVo.Success(noticeService.getById(noticeId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增或修改")
    public ResponseBodyVo<MqNotice> save(@RequestBody @ApiParam("内容") MqNotice notice) {
        noticeService.saveOrUpdate(notice);
        return ResponseBodyVo.Success(notice);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "公告删除")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@RequestParam("id") String id, @TenantId String tenantId) {
        return ResponseBodyVo.Success(noticeService.delete(id, tenantId));
    }


}
